package com.starblink.login.createaccount.inputemail.ui

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.apollographql.apollo3.api.Optional
import com.starblink.android.basic.base.BaseViewModel
import com.starblink.android.basic.ext.toast
import com.starblink.android.basic.network.base.SkGqlClient
import com.starblink.basic.util.CommUtils
import com.starblink.login.R
import com.starblink.rocketreserver.CheckingAccountDoesItExistQuery
import kotlinx.coroutines.launch

class CreateAccountInputEmailVM : BaseViewModel() {
    val checkResultLiveData: MutableLiveData<Boolean> = MutableLiveData()

    fun checkEmailExist(email: String) {
        viewModelScope.launch {
            val response = SkGqlClient.skQuery(
                CheckingAccountDoesItExistQuery(
                    email = Optional.present(email)
                ),
                showDefaultLoading = true
            )
            if (response?.data != null && response.data!!.checkingAccountDoesItExist != null) {
                checkResultLiveData.postValue(response.data!!.checkingAccountDoesItExist!!)
            }
        }
    }
}